/*
 *接口编写处...
*如果接口需要做Action的权限验证，请在Action上使用属性
*如: [ApiActionPermission("Flower",Enums.ActionPermissionOptions.Search)]
 */
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using VOL.Entity.DomainModels;
using VOL.Dongxing.IServices;
using VOL.Entity.DomainModels.Dto;
using VOL.Dongxing.Repositories;
using VOL.Dongxing.IRepositories;
using System.Linq;
using System.Net;

namespace VOL.Dongxing.Controllers
{
    public partial class FlowerController
    {
        private readonly IFlowerService _service;//访问业务代码
        private readonly IHttpContextAccessor _httpContextAccessor;

        [ActivatorUtilitiesConstructor]
        public FlowerController(
            IFlowerService service,
            IHttpContextAccessor httpContextAccessor
        )
        : base(service)
        {
            _service = service;
            _httpContextAccessor = httpContextAccessor;
        }


        [HttpPost, Route("GetFlowerList")]
        public async Task<IActionResult> GetFlowerList([FromBody] FlowerInfo flowerInfo)
        {
            int pageSize = 10;
            int skip = (flowerInfo.Page - 1) * pageSize;
            IFlowerRepository repository = FlowerRepository.Instance;
            var data = repository.DbContext.Set<Flower>().Skip(skip).Take(pageSize).ToList();
            int current_page = flowerInfo.Page;

            int num = repository.DbContext.Set<Flower>().Count();
            double result = num / pageSize;
            int last_page = (int)Math.Ceiling(result);

            // 创建类的实例，并设置其属性
            ListRes obj = new ListRes
            {
                Data = data,
                Current_Page = current_page,
                Last_Page = last_page,
            };


            return Json(obj);

            //return Json(await Service.GetFlowerList(flowerInfo));
        }

    }
}
